package com.cw.jeeyt.service.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.cw.jeeyt.service.intf.system.InitializeDataService;

/**
 * 初始化框架数据库
 *
 * @author chenw
 */
@Component
public class FrameDbInitListener implements ApplicationListener<ApplicationStartedEvent> {

    private static final Logger logger = LoggerFactory.getLogger(FrameDbInitListener.class);
    @Autowired
    private InitializeDataService initializeDataService;

    /**
     * 框架数据库表初始化
     *
     * @param event
     * @see
     */
    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        logger.info("---init base data...");
        try {
            initBasicData();
        } catch (Exception e) {
            e.printStackTrace();
        }
        logger.info("---init base data finished--。");
    }

    /**
     * 更新系统运行需要的基础数据
     */
    private void initBasicData() throws Exception {
        initializeDataService.initData();
    }
}
